﻿using System.Reflection;
using ZilLion.TaskManager.Entity.Entity;

namespace ZilLion.TaskManager.Core.Command
{
    /// <summary>
    ///     命令执行工厂
    /// </summary>
    public class CommandFactory
    {
        /// <summary>
        ///     执行命令
        /// </summary>
        /// <param name="commandInfo"></param>
        public static void Execute(TaskConmmandEntity commandInfo)
        {
            var namespacestr = typeof(BaseCommand).Namespace;
            var obj =
                Assembly.GetAssembly(typeof(BaseCommand))
                    .CreateInstance(namespacestr + "." + commandInfo.Commandname + "Command", true);
            if ((obj != null) && obj is BaseCommand)
            {
                var command = obj as BaseCommand;
                command.CommandInfo = commandInfo;
                command.Execute();
            }
        }
    }
}